package com.huabo.system.service.impl;


import com.hbfk.entity.DealUserToken;
import com.hbfk.entity.TblStaffUtil;
import com.hbfk.util.PageInfo;
import com.huabo.system.mysql.entity.TblYyOrgDepositMySql;
import com.huabo.system.mysql.entity.TblYyUserOrderMySql;
import com.huabo.system.mysql.mapper.TblYyOrgDepositMySqlMapper;
import com.huabo.system.mysql.mapper.TblYyUserOrderMySqlMapper;
import com.huabo.system.oracle.entity.TblYyOrgDeposit;
import com.huabo.system.oracle.entity.TblYyUserOrder;
import com.huabo.system.oracle.mapper.TblYyOrgDepositMapper;
import com.huabo.system.oracle.mapper.TblYyUserOrderMapper;
import com.huabo.system.service.TblYyUserOrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class TblYyUserOrderServiceImpl implements TblYyUserOrderService {

    @Resource
    private TblYyOrgDepositMapper tblYyOrgDepositMapper;

    @Resource
    private TblYyUserOrderMapper tblYyUserOrderMapper;

    @Resource
    private TblYyOrgDepositMySqlMapper tblYyOrgDepositMySqlMapper;

    @Resource
    private TblYyUserOrderMySqlMapper tblYyUserOrderMySqlMapper;


    @Override
    public Map<String, Object> selectPageInfoList(String token, String staffId, Integer pageNumber, Integer pageSize, TblYyUserOrder yuo) {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        try {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            TblYyOrgDeposit yod = tblYyOrgDepositMapper.selectOrgDepositByOrgId(staff.getCurrentOrg().getOrgid());
            Double price = 0.0;
            if (yod != null) {
                price = yod.getTotalmoney() - yod.getTotalpaymoney();
            }
            PageInfo<TblYyUserOrder> pageInfo = new PageInfo<TblYyUserOrder>();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            yuo.setOrgid(staff.getCurrentOrg().getOrgid());
            pageInfo.setCondition(yuo);
            pageInfo.setTlist(tblYyUserOrderMapper.selectListByPageInfo(pageInfo));
            pageInfo.setTotalRecord(tblYyUserOrderMapper.selectCountByPageInfo(pageInfo));
            Map<String, Object> dataMap = new HashMap<String, Object>(0);
            dataMap.put("money", Float.valueOf(price.toString()));
            dataMap.put("pageInfo", pageInfo);
            resultMap.put("code", "1");
            resultMap.put("msg", "数据访问成功");
            resultMap.put("data", dataMap);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resultMap;
    }

    @Override
    public Map<String, Object> selectMySqlPageInfoList(String token, String staffId, Integer pageNumber, Integer pageSize, TblYyUserOrderMySql yuo) {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        try {
            TblStaffUtil staff = DealUserToken.parseUserToken(token);
            TblYyOrgDepositMySql yod = tblYyOrgDepositMySqlMapper.selectOrgDepositByOrgId(staff.getCurrentOrg().getOrgid());
            Double price = 0.0;
            if (yod != null) {
                price = yod.getTotalmoney() - yod.getTotalpaymoney();
            }
            PageInfo<TblYyUserOrderMySql> pageInfo = new PageInfo<TblYyUserOrderMySql>();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            yuo.setOrgid(staff.getCurrentOrg().getOrgid());
            pageInfo.setCondition(yuo);
            pageInfo.setTlist(tblYyUserOrderMySqlMapper.selectListByPageInfo(pageInfo));
            pageInfo.setTotalRecord(tblYyUserOrderMySqlMapper.selectCountByPageInfo(pageInfo));
            Map<String, Object> dataMap = new HashMap<String, Object>(0);
            dataMap.put("money", Float.valueOf(price.toString()));
            dataMap.put("pageInfo", pageInfo);
            resultMap.put("code", "1");
            resultMap.put("msg", "数据访问成功");
            resultMap.put("data", dataMap);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resultMap;
    }


}

